package code301_400;

import java.util.HashMap;
import java.util.Map;

public class Code390 {
    public boolean wordPattern(String pattern, String s) {
        String[] arr = s.split(" ");
        char[] charr =pattern.toCharArray();
        if(arr.length!=charr.length)
            return false;
        Map<Character,String> map = new HashMap<Character,String>();
        for(int i=0;i<charr.length;i++){
            if(map.get(charr[i])!=null) {
                if (map.get(charr[i]).equals(arr[i])) {
                    continue;
                }
                return false;
            }else {
                if(map.containsValue(arr[i])){
                    return false;
                }
                map.put(charr[i],arr[i]);
            }

        }
        return true;
    }
}
